[ Home | Prev | Next ]

Chapter 9: continued


Customizing Desktop Scripts

The desktop scripts that come with Frontier are useful as is, but we obviously couldn't anticipate all the tasks you might want to automate. Since they're written in UserTalk, you can change them to fit your needs. We'll look at two possible changes to these scripts here; realize that these examples are simply designed to get your creative juices flowing about things you might do with these desktop scripts.

Counting Other Kinds of Files

The most obvious way you could customize the first example, countWordFiles, would be to look for files other than Microsoft Word files. You can do so by opening the script in Frontier (while holding the Command key) and making these simple changes: Here, for example, is the countWordFiles script, modified to look for Frontier files and renamed countFrontierFiles.

If you want to get really ambitious, you could write a script that would prompt the user with the standard file dialog box, get that application's four-character creator type, and then use the result to count the files. These tasks, as authors of the college textbooks say, are exercises left to the reader.

Using a Folder's Date as a Starting Point

Our second example, the "Recently Changed Files" script, has the default date entered directly as a value. Programmers call this "hard coding" information and it's generally not a good idea. One solution is to have the script suggest a date based on the current date, perhaps one week earlier. Change the line that now reads:
s = "October 1, 1991"

to

s = clock.now () - (7 * 24 * 60 * 60)

This statement subtracts from the present day and time the value of seven days times 24 hours per day times 60 minutes per hour times 60 seconds per minute. It produces a time exactly 168 hours before the present time.

You could use other approaches to the problem of the hard-coded date. For example, you could check to see if the folder called "Recently Changed Files" exists and, if it does, use the file.modified verb to get its modified date. This approach lets you gather only files that have changed since the last time you gathered changed files.

Creating Desktop Scripts

Most desktop scripts deal with operations that make sense at the Finder level, involving things like files, folders, and system issues. But that is not necessary. Any UserTalk script that you'd like a user to be able to launch by double-clicking it in the Finder can be made into a desktop script.

A desktop script must use the "on" keyword approach to its format. It must also take a single parameter, Frontier will fill in the path of the folder in which the desktop script is stored (or the volume on which it is located if it is not placed into a folder).

To make a UserTalk script into a desktop script, all you have to do is choose "Export a Desktop Script..." from the UserLand menu in Frontier. You can also use this command's keyboard equivalent, Command-3. You'll be asked (Figure 3-1) which script you want to export as a desktop script. The name of the selected object will be offered as a default response.


Figure 3-1. Dialog for Exporting a Script to the Desktop

Once you indicate the name of the object you wish to export, either by accepting Frontier's suggested response or by typing in your own table address, you will be presented with the standard Macintosh file dialog to specify name and location.

Before you give a desktop script to another user to work with, we recommend that you test it on at least one system other than your own to check for errors such as including a reference to a specific hard disk.

One final tip. If the window for the folder or volume to which you export the desktop script is open when you export the script, you may have to close the folder and then re-open it for the desktop script to be able to be launched with a double-click. This limitation is one of the quirks of the System 7 Finder.

Contents Page | Previous Section | Next Chapter -- Suites and Agents
HTML formatting by Steven Noreyko January 1996, User Guide revised by UserLand June 1996